﻿using UnityEngine;
using System.Collections;

public class CameraFollow : MonoBehaviour {

    public Transform target;
    public float distanceH = 10f;
    public float distanceV = 5f;


    // Use this for initialization
    void Start () {
        
    }

    // Update is called once per frame
    void Update () {

    }

    public float smoothSpeed = 10f; //平滑参数

    void LateUpdate()
    {
        if (Input.GetMouseButton(1)) {
            float cam_h = Input.GetAxis("Mouse X");

            if (cam_h != 0) {
                //Debug.Log("cam_h:" + cam_h);
            }

            Vector3 v3 = target.position;
            v3.y = transform.position.y;

            transform.RotateAround(v3, Vector3.up, cam_h * 10f);

            transform.LookAt(target);
        }

        //if (Vector2.Distance(transform.position, target.position) < distanceH * 1.2f) {
        //    Vector3 nextpos = Vector3.forward * -1 * distanceH + Vector3.up * distanceV + target.position;

        //    transform.position = Vector3.Lerp(this.transform.position, nextpos, smoothSpeed * Time.deltaTime); //平滑插值
        //}


    }

    // void LateUpdate()
    // {
    //     Vector3 nextpos = Vector3.forward * -1 * distanceH + Vector3.up * distanceV + target.position;
    //     this.transform.position = nextpos;
    //     this.transform.LookAt(target);
    // }
}